home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / GW AdaEd 1.4.2 / GWAdaDemos / GWU Demos / room.adb < prev    next >
Text File  |  1993-02-11  |  2KB  |  89 lines

  1. --::::::::::
  2. --roomline.adb
  3. --::::::::::
  4. WITH Text_IO;
  5. WITH Chop;
  6. WITH Phil;
  7. WITH Calendar;
  8. --PRAGMA Elaborate(Phil);
  9. PACKAGE BODY Room IS
  10.  
  11. -- A line-oriented version of the Room package, for line-oriented
  12. -- terminals like IBM 3270's where the user cannot do ASCII screen control.
  13. -- This is the only file in the dining philosophers system that needs
  14. -- changing to use in a line-oriented environment.
  15. -- Michael B. Feldman, The George Washington University, November 1990.
  16.  
  17.  
  18.   Phils:      ARRAY(Table_Type) OF Phil.Philosopher;
  19.  
  20.   TYPE Phil_Names IS (Dijkstra, Texel, Booch, Ichbiah, Stroustrup);
  21.  
  22.   TASK BODY Head_Waiter IS
  23.  
  24.     T : Integer;
  25.     Start_Time: Calendar.Time;
  26.     Phil_Names: CONSTANT ARRAY(1..5) OF String(1..18) :=
  27.      ("Eddy Dijkstra     ",
  28.       "Putnam Texel      ",
  29.       "Grady Booch       ",
  30.       "Jean Ichbiah      ",
  31.       "Bjarne Stroustrup ");
  32.     Blanks : CONSTANT String := "     ";
  33.  
  34.   BEGIN
  35.  
  36.     ACCEPT Open_The_Room;
  37.     Start_Time := Calendar.Clock;
  38.  
  39.     Phils(1).Come_To_Life(1,1,2);
  40.     Phils(3).Come_To_Life(3,3,4);
  41.     Phils(2).Come_To_Life(2,2,3);
  42.     Phils(5).Come_To_Life(5,1,5);
  43.     Phils(4).Come_To_Life(4,4,5);
  44.  
  45.     LOOP
  46.       SELECT
  47.         ACCEPT Report_State(Which_Phil: Table_Type;
  48.                          State: Phil.States;
  49.                          How_Long: Natural := 0) DO
  50.           T := Integer(Calendar."-"(Calendar.Clock,Start_Time));
  51.           Text_IO.Put( "T=" & Integer'Image(T) & " "
  52.             & Blanks(1..Which_Phil) & Phil_Names(Which_Phil));
  53.  
  54.           CASE State IS
  55.  
  56.             WHEN Phil.Breathing =>
  57.               Text_IO.Put("Breathing");
  58.             WHEN Phil.Thinking =>
  59.               Text_IO.Put( "Thinking"
  60.                          & Integer'Image(How_Long)
  61.                          & " seconds.");
  62.             WHEN Phil.Eating =>
  63.               Text_IO.Put( "Eating"
  64.                          & Integer'Image(How_Long)
  65.                          & " seconds.");
  66.             WHEN Phil.Done_Eating =>
  67.               Text_IO.Put("Yum-yum (burp)");
  68.             WHEN Phil.Got_One_Stick =>
  69.               Text_IO.Put( "First chopstick"
  70.                           & Integer'Image(How_Long));
  71.             WHEN Phil.Got_Other_Stick =>
  72.               Text_IO.Put( "Second chopstick"
  73.                           & Integer'Image(How_Long));
  74.  
  75.           END CASE;
  76.           Text_IO.New_Line;
  77.  
  78.          END Report_State;
  79.         OR
  80.           TERMINATE;
  81.         END SELECT;
  82.  
  83.       END LOOP;
  84.  
  85.     END Head_Waiter;
  86.  
  87. END Room;
  88.  
  89.